package com.spring.theory.bean.scope;

import com.spring.theory.bean.scope.type.BeanOfPrototype;
import com.spring.theory.bean.scope.type.BeanOfSingleton;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * Scope类型
 * - singleton(单例bean)、prototype（新建bean）、request（生命周期随请求）、session（随会话）、application（随应用webServletContext域）
 *
 * @author H
 * @version 1.0
 * @date 2023-12-27 14:38
 */
@Slf4j
@SpringBootApplication
public class TestScope {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(TestScope.class, args);
        log.info("beanOfSingleton,1==>{}", context.getBean("beanOfSingleton", BeanOfSingleton.class));
        log.info("beanOfSingleton,2==>{}", context.getBean("beanOfSingleton", BeanOfSingleton.class));
        log.info("beanOfPrototype,1==>{}", context.getBean("beanOfPrototype", BeanOfPrototype.class));
        log.info("beanOfPrototype,2==>{}", context.getBean("beanOfPrototype", BeanOfPrototype.class));
    }

}
